<?php
	/* ===========================================
	 *			Lambda Framework 1.0.0
	 *
	 *	Developer: Andre 'AndyStyle96' Mohnert
	 *		(c) 2013 by mohnertsoft Ltd.
	 * =========================================== */
	 
	class MySQL
	{
		private $db;
		private $lastQuery;
		private $lastSQL;
		
		public function __construct()
		{
			$this->initConnection();
		}
		
		public function __destruct()
		{
			$this->closeConnection();
		}
		
		public function closeConnection()
		{
			mysql_close($this->db);
		}
		
		public function freeResult($query = null)
		{
			if($query == null)
				mysql_free_result($this->lastQuery);
			else
				mysql_free_result($query);
		}
		
		public function getArray($query = null)
		{
			if($query == null)
				$row = mysql_fetch_array($this->lastQuery);
			else
				$row = mysql_fetch_array($query);
			return $row
		}
		
		public function getAssoc($query = null)
		{
			if($query == null)
				$row = mysql_fetch_assoc($this->lastQuery);
			else
				$row = mysql_fetch_assoc($query);
			return $row;
		}
		
		public function getNumRow($query = null)
		{
			if($query == null)
				$row = mysql_num_rows($this->lastQuery);
			else
				$row = mysql_num_rows($query);
			return $row;
		}
		
		public function getObject($query = null)
		{
			if($query == null)
				$row = mysql_fetch_object($this->lastQuery);
			else
				$row = mysql_fetch_object($query);
			return $row;
		}
		
		public function getResult($query = null, $row = 0, $field = 0)
		{
			if($query == null)
				$result = mysql_result($this->lastQuery, $row, $field);
			else
				$result = mysql_result($query, $row, $field);
			return $result;
		}
		
		public function getRow($query = null)
		{
			if($query == null)
				$row = mysql_fetch_row($this->lastQuery);
			else
				$row = mysql_fetch_row($query);
			return $row;
		}
		
		public function secureString($str)
		{
			return mysql_real_escape_string($str);
		}
		
		public function selectDB($newDB)
		{
			if(!mysql_select_db($newDB, $this->db))
				die('No MySQL connection.<br />'.mysql_error());
		}
		
		public function sendQuery($sql)
		{
			$this->lastSQL = $sql;
			$this->lastQuery = mysql_query($this->lastSQL);
			return $this->lastQuery;
		}
		
		
		private function initConnection()
		{
			global $database;
			$this->db = mysql_connect($database['hostname'], $database['user'], $database['pwd']);
			if(!mysql_select_db($database['db'], $this->db))
				die('No MySQL connection.<br />'.mysql_error());
		}
	}
?>